<template>
  <div id="">
    <router-view class="childrenPage"></router-view>

    <headerbox :headerTitle="'圈子'" :hasBack='false' :hasPublish='true' @publishEvent="publishEvent"></headerbox>

    <v-scroll :on-refresh="onRefresh" :on-infinite="enableInfinite ? onInfinite : undefined">
      <noneList v-if="actyList.length==0" :noneTxt="'暂无好友状态，快去添加好友吧~'"></noneList>
      <div v-else>
        <playActy v-for="acty in actyList" :key="acty.key" :acty="acty" class="mb10"></playActy>
      </div>
    </v-scroll>

    <footerNav></footerNav>
  </div>
</template>
<script>
import { circleArticleList } from '@/utils/ajaxRequest.js';
import vScroll from '@/components/loadMore/loadMore';
export default {
  name: "",
  data: () => ({
    actyList:[],
    token:'',
    pageNo:1,
    enableInfinite:true,
  }),
  components: {
    playActy:()=>import('./playActy/playActy'),
    noneList:()=>import('@/components/noneList/noneList'),
    vScroll,
  },
  methods: {
    onRefresh(done) {   //刷新
      this.pageNo = 1;
       this.getCircleArticleList();
       done() // call done
    },
    onInfinite(done) {    //加载
        let self = this;
        self.enableInfinite = false;
        this.pageNo++;
        this.getCircleArticleList();
        done();
     },
    publishEvent(data) {
      console.log(data);
      this.$router.push({name:'publishCircle'});
    },
    // 获取圈子文章列表
    getCircleArticleList() {
      let self = this;
      let articleParam = {
        token:self.token,
        currentPage:self.pageNo
      }
      circleArticleList(articleParam).then(res=>{
        console.log(res);
        if(res){
          console.log(self.pageNo);
          let result = res.data.result;
          if (result.length<1) {
            self.enableInfinite = false;    //关闭上拉加载
            // self.toast('没有更多了');
          }else{
            self.enableInfinite = true;     //打开上拉加载
          }
          if (self.pageNo==1) {
            self.actyList = result;
          }else{
            self.actyList = self.actyList.concat(result);
          }
        }
      })
    }
  },
  mounted() {
    //do something after mounting vue instance
    let xlyd_loginInfo = JSON.parse(window.localStorage.getItem('xlyd_loginInfo'));
    if (!xlyd_loginInfo) {
      self.messageBox.confirm('您还未登录，暂无圈友信息，前往登录？').then(active=>{
        self.$router.push({name:'login'});
      }).catch(error=>{
        console.log(error);
      });
      return false;
    }
    this.token = xlyd_loginInfo.token;
    this.getCircleArticleList();
  }
}
</script>
<style lang="scss" scoped>

</style>
